<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>旋转</title>
		<style type="text/css">
			* {
				padding: 0;
				margin: 0;
			}
			
			.container {
				width: 100vw;
				height: 100vh;
				display: flex;
				align-items: center;
				justify-content: center;
			}
			
			canvas {
				width: 500px;
				height: 500px;
				border: 2px solid blue;
			}
			
		</style>
	</head>

	<body>
		<div class="container">
			<canvas id="canvas" width="500" height="500"></canvas>
		</div>
	</body>
	<script type="text/javascript">
		window.onload = function() {
			let oCanvas = document.getElementById('canvas');
			console.dir(oCanvas);
			let oPen = oCanvas.getContext("2d");
			
			oPen.fillStyle="darkblue";
			let x=200,
			    y=200,
			    width=100,
			    height=100;
			oPen.fillRect(x,y,width,height);
			
			/*rotate(角度)*/
			setInterval (function(){
			oPen.translate(x+width/2,y+height/2);
			oPen.rotate(Math.PI/180*30);
			oPen.translate(-(x+width/2),-(y+height/2));
			oPen.clearRect(0,0,500,500);
			oPen.fillRect(x,y,width,height);
			 },100)
		}
	</script>
	</body>

</html>